package com.atguigu.srb.result;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 * ClassName: ResponseVo
 * Package: com.atguigu.srb.result
 * Description:
 *
 * @Author 刘强
 * @Create 2024/4/15 14:25
 * @Version 1.0
 */
// 统一响应的结果类
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("响应的结果类")
public class ResponseVo {
    @ApiParam("响应的业务状态码")
    private Integer code;
    @ApiParam("响应的描述消息")
    private String message;
    @ApiParam("响应的数据")
    private Map<String ,Object> data = new HashMap<>();

    public static ResponseVo ok(){
        ResponseVo responseVo = new ResponseVo();
        responseVo.setCode(ResponseEnum.SUCCESS.getCode());
        responseVo.setMessage(ResponseEnum.SUCCESS.getMessage());
        return responseVo;
    }
    public static ResponseVo ok(Map<String ,Object> data){
        ResponseVo responseVo = new ResponseVo();
        responseVo.setCode(ResponseEnum.SUCCESS.getCode());
        responseVo.setMessage(ResponseEnum.SUCCESS.getMessage());
        responseVo.setData(data);
        return responseVo;
    }

    public static ResponseVo error(){
        ResponseVo responseVo = new ResponseVo();
        responseVo.setCode(ResponseEnum.ERROR.getCode());
        responseVo.setMessage(ResponseEnum.ERROR.getMessage());
        return responseVo;
    }
    public static ResponseVo setResult(ResponseEnum responseEnum){
        ResponseVo responseVo = new ResponseVo();
        responseVo.setCode(responseEnum.getCode());
        responseVo.setMessage(responseEnum.getMessage());
        return responseVo;
    }


    // 链式调用
    public ResponseVo code(Integer code){
        this.setCode(code);
        return this;
    }
    public ResponseVo message(String message){
        this.setMessage(message);
        return this;
    }
    public ResponseVo addData(String key,Object value){
        this.getData().put(key,value);
        return this;
    }

}
